<?php
/**
 * Created by PhpStorm.
 * User: 熵
 * Date: 2021/12/12
 * Time: 21:16
 */
require 'dbtool.php';
$username=$_POST['username'];
$psd=$_POST['psd'];
$newUrl='';
$msg='';
session_start();
$conn=new mysqli();
$conn->connect('127.0.0.1','root','root','bank');
if(!empty($conn->connect_error)){
    echo 'MYSQL数据库连接错误: '.$conn->connect_error;
}
dbtool::setconn($conn);
$data=dbtool::selectconn('select * from bankcard');
print_r($data);
for($i=0;$i<count($data);$i++){
    if($username==$data[$i]['CardNo']&&$psd==$data[$i]['CardPwd']){
        $keyValue=md5($username.$psd);
        setcookie('userkey',$keyValue,time()+24*3600);
        $newUrl='userinfo.php';
        $msg='登录成功';
        $_SESSION[$keyValue]=['username'=>$username,'psd'=>$psd];
        break;
    }
    else{
        $msg='登录失败';
        $newUrl='../login.php';
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
    <input type="hidden" id="newUrl" value="<?php echo $newUrl;?>" />
    <input type="hidden" id="msg" value="<?php echo $msg;?>" />
</body>
<script>
    onload=function (){
        var newUrl= document.getElementById('newUrl').value;
        var msg=document.getElementById('msg').value;
        alert(msg);
        location.href=newUrl;
    }
</script>

</html>
